package com.macro.mall.controller;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.dto.BmsExhibitionsActivitiesParam;
import com.macro.mall.model.BmsExhibitionsActivities;
import com.macro.mall.service.BmsExhibitionsActivitiesService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 展览活动Controller
 * Created by macro on 2018/4/26.
 */
@Controller
@Api(tags = "BmsExhibitionsActivitiesController")
@Tag(name = "BmsExhibitionsActivitiesController", description = "展览活动管理")
@RequestMapping("/exhibitionsActivities")
public class BmsExhibitionsActivitiesController {
    @Autowired
    private BmsExhibitionsActivitiesService bmsExhibitionsActivitiesService;

    @ApiOperation("添加展览活动")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> create(@RequestBody BmsExhibitionsActivitiesParam bmsExhibitionsActivitiesParam) {
        int count = bmsExhibitionsActivitiesService.create(bmsExhibitionsActivitiesParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }


    @ApiOperation("修改展览活动")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> update(@RequestBody BmsExhibitionsActivitiesParam bmsExhibitionsActivitiesParam) {
        int count = bmsExhibitionsActivitiesService.update(bmsExhibitionsActivitiesParam);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }
    @ApiOperation("分页查询展览活动")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CommonPage<BmsExhibitionsActivities>> getList(@RequestBody BmsExhibitionsActivitiesParam bmsExhibitionsActivitiesParam) {
        List<BmsExhibitionsActivities> bmsExhibitionsActivitiesList = bmsExhibitionsActivitiesService.getList(bmsExhibitionsActivitiesParam);
        return CommonResult.success(CommonPage.restPage(bmsExhibitionsActivitiesList));
    }

    @ApiOperation("根据id获取展览活动信息")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<BmsExhibitionsActivities> getItem(@PathVariable Long id) {
        BmsExhibitionsActivities bmsExhibitionsActivities = bmsExhibitionsActivitiesService.getItem(id);
        return CommonResult.success(bmsExhibitionsActivities);
    }

    @ApiOperation("删除展览活动")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> delete(@RequestBody List<Long> ids) {
        try {
            return CommonResult.success(bmsExhibitionsActivitiesService.delete(ids));
        } catch (Exception e) {
            return CommonResult.failed(e.getMessage());
        }
    }


//    @ApiOperation("小程序展览活动首页")
//    @RequestMapping(value = "/mpList", method = RequestMethod.POST)
//    @ResponseBody
//    public CommonResult<?> mpList() {
//
//    }

}
